package de.tu_darmstadt.gdi1.towerdefense.ui;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * panel with buttons for building, selling and upgrading towers
 */
public class TowerFrame extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5500849081044840251L;
	private ArrayList<JButton> buttons;

	/**
	 * constructor
	 */
	public TowerFrame() {
		buttons = new ArrayList<JButton>();
		setLayout(new GridLayout(4, 1));

		JButton button = new JButton("Build Damage Tower");
		button.setActionCommand("Build Damage Tower");
		button.setToolTipText("<html>Damage Tower <br>"
				+ "<html>Cost: 500 <br>" + "<html>Upgrade Cost: 500 <br>"
				+ "<html>Damage: 10 <br>" + "<html>Cooldown: 2 <br>"
				+ "<html>Basic Tower, relatively fast but low range.");
		buttons.add(button);

		button = new JButton("Build Sniper Tower");
		button.setActionCommand("Build Sniper Tower");
		button.setToolTipText("<html>Sniper Tower <br>"
				+ "<html>Cost: 1000 <br>"
				+ "<html>Upgrade Cost: 1000 <br>"
				+ "<html>Damage: 50 <br>"
				+ "<html>Cooldown: 5 <br>"
				+ "<html>Sniper Tower, relatively slow <br>but high range and high damage.");
		buttons.add(button);

		button = new JButton("Upgrade Tower");
		button.setActionCommand("Upgrade Tower");
		button.setToolTipText("Upgrade the tower to the next level.");
		buttons.add(button);

		button = new JButton("Destroy Tower");
		button.setActionCommand("Destroy Tower");
		button.setToolTipText("Destroy the tower and get half the money back.");
		buttons.add(button);
		for (Iterator<JButton> bts = buttons.iterator(); bts.hasNext();) {
			JButton b = bts.next();
			add(b);
		}
		setSize(200, 600);
	}

	/**
	 * add an action listener to the buttons
	 * 
	 * @param a
	 *            the action listener
	 */
	public void addListener(ActionListener a) {
		for (JButton button : buttons) {
			button.addActionListener(a);
		}
	}

}